********************************************************************************************************************************
***   Replication file for:                                                                                                  ***
***   Braun, S. T. and Stuhler, J. (2024). The Economic Consequences of Being Widowed by War: A Life-Cycle Perspective.	     ***
***	  Journal of Public Economics                                                                                            ***
***   							                                                                                             ***
***   ---   Main Do-File   ---   																							 ***
***	  --- 	Mikrozensus Zusatzerhebung 1971                                                                                  ***
***
***   Software:
***   Analyses run on Windows using Stata version 17 
***
***   Notes: 
***	  Data are stored in /data
***   Tables are outputted to /results/tables
***   To perform, a clean run delete the following folders: /results, /processed
***
***
********************************************************************************************************************************

*** Users must define global macro to point to the folder that contains the main do file
*** This directory is where results are stored
global widowsdir ""

* Confirm that the global for the project root directory was defined
assert !missing("$widowsdir")

* Initialize log
clear
set more off
cap mkdir "$widowsdir/scripts/logs"
cap log close
local datetime : di %tcCCYY.NN.DD!-HH.MM.SS `=clock("$S_DATE $S_TIME", "DMYhms")'
local logfile "$widowsdir/scripts/logs/`datetime'.log.txt"
log using "`logfile'", text

* Configure Stata's library environment and record system parameters
run "$widowsdir/scripts/_config.do"

* Stata version control
version 17

* Create directories for output files
cap mkdir "$widowsdir/results"
cap mkdir "$widowsdir/results/tables"
cap mkdir "$widowsdir/processed"

* Run project analysis
do "$widowsdir/scripts/1-mzu71-dataprep" 
do "$widowsdir/scripts/2-mzu71-descriptives.do"
do "$widowsdir/scripts/3-mzu71-regressions.do"

* End log
di "End date and time: $S_DATE $S_TIME"
log close

exit